package com.uit.project.bustrip.adapter;

import java.util.ArrayList;

import com.uit.project.bustrip.R;
import com.uit.project.bustrip.entity.Point;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListPointAdapter extends ArrayAdapter<Point>{
	private ArrayList<Point> items;
	private Activity context;
	public ListPointAdapter(Activity context, ArrayList<Point> items) {
		super(context, R.layout.activity_list_point_item, items);
		this.items = items;
		this.context = context;
	}
	static class ViewHolder {
		protected TextView pointName;
		protected TextView routeCode;
		protected TextView tripCode;
		protected TextView position;
	}
	/* (non-Javadoc)
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final Point item = items.get(position);
		View v = null;
		if (convertView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			v = inflater.inflate(R.layout.activity_list_point_item, null);
			final ViewHolder vh = new ViewHolder();
			vh.pointName = (TextView) v.findViewById(R.id.pointName);
			vh.routeCode = (TextView) v.findViewById(R.id.routeCode);
			vh.tripCode = (TextView) v.findViewById(R.id.tripCode);
			vh.position = (TextView) v.findViewById(R.id.position);
			v.setTag(vh);
		}
		else{
			v = convertView;
		}
		ViewHolder holder = (ViewHolder) v.getTag();
		holder.pointName.setText(item.pointname);
		holder.routeCode.setText(item.routeCode);
		holder.tripCode.setText(item.tripCode);
		holder.position.setText(String.valueOf(item.position));
		return v;
	}
}
